package com.example.controller;

import com.example.constant.ResultCodeConstant;
import com.example.dto.AnnouncementDTO;
import com.example.dto.AnnouncementQuery;
import com.example.entity.AnnouncementDO;
import com.example.response.RestResult;
import com.example.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 宣传信息管理Controller
 * </p>
 * @author 34448
 */
@Api("宣传信息管理")
@RequestMapping("announcement")
@RestController
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    /**
     * 发布宣传信息
     *
     * @param announcementDTO 宣传信息DTO
     * @param userId 用户ID
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("发布宣传信息")
    public RestResult<Boolean> addAnnouncement(@RequestBody @Validated AnnouncementDTO announcementDTO, @RequestParam Integer userId) {
        Boolean result = announcementService.addAnnouncement(announcementDTO, userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改宣传信息
     *
     * @param announcementDTO 宣传信息DTO
     * @param userId 用户ID
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改宣传信息")
    public RestResult<Boolean> updateAnnouncement(@RequestBody @Validated AnnouncementDTO announcementDTO, @RequestParam Integer userId) {
        Boolean result = announcementService.updateAnnouncement(announcementDTO, userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除宣传信息
     *
     * @param announcementId 公告ID
     * @param userId 用户ID
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除宣传信息")
    public RestResult<Boolean> deleteAnnouncement(@RequestParam @NotNull Integer announcementId, @RequestParam Integer userId) {
        Boolean result = announcementService.deleteAnnouncement(announcementId, userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询宣传信息
     *
     * @param announcementQuery 查询条件
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("查询宣传信息")
    public RestResult<List<AnnouncementDO>> queryAnnouncements(AnnouncementQuery announcementQuery) {
        List<AnnouncementDO> result = announcementService.queryAnnouncements(announcementQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导入宣传信息
     *
     * @param filePath 文件路径
     * @param userId 用户ID
     * @return
     */
    @PostMapping("/import")
    @ApiOperation("导入宣传信息")
    public RestResult<Boolean> importAnnouncements(@RequestParam @NotNull String filePath, @RequestParam Integer userId) {
        Boolean result = announcementService.importAnnouncements(filePath, userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导出宣传信息
     *
     * @param announcementIds 公告ID列表
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/export")
    @ApiOperation("导出宣传信息")
    public RestResult<List<AnnouncementDO>> exportAnnouncements(@RequestParam(required = false) List<Integer> announcementIds, @RequestParam Integer userId) {
        List<AnnouncementDO> result = announcementService.exportAnnouncements(announcementIds, userId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}